# tushare_mirror/utils.py
import os
from .config import Config
from vnpy.trader.constant import Exchange

def detect_exchange(symbol: str) -> Exchange:
    """根据股票代码推断交易所"""
    if symbol.startswith(("600", "601", "603", "688")):
        return Exchange.SSE
    elif symbol.startswith(("000", "002", "300")):
        return Exchange.SZSE
    elif symbol.startswith(("43", "83", "87", "88")):
        return Exchange.BSE
    else:
        raise ValueError(f"无法识别的股票代码: {symbol}")

def get_cache_path(symbol: str) -> str:
    """生成缓存文件路径"""
    return os.path.join(
        Config.DATA_PATH,
        f"{symbol}_daily.csv"
    )